var domain="http://www.qiyedaishu.com";
//var domain="http://192.168.31.24";
var login_domain=domain+"/tools/Login.ashx";
var index_domain=domain+"/tools/Index.ashx";
var oa_domain=domain+"/tools/OA.ashx";
var crm_domain=domain+"/tools/CRM.ashx";
var admin_domain=domain+"/tools/Admin.ashx";
var upload_domain=domain+"/tools/Upload.ashx";
var PAGE_SIZE10 = 10;
var PAGE_SIZE20 = 20;
var source=3 // 1代表pc  2代表android  3.代表ios
var version="";
var editions="";
var userid=0;
var comid=0;
var now=new Date();
var User={};
var swidth=document.documentElement.clientWidth;
var sheight=document.documentElement.clientHeight;
var requests; //全局ajax请求变量
var pswps;
var obj;
var obj10;
var pos_map;
var pageindex=1;
function get(id)
{
	return document.getElementById(id);
};

function getJSON(url,data,fun){
	var xhr = new plus.net.XMLHttpRequest();
	xhr.onreadystatechange = function () {
		switch ( xhr.readyState ) {
			case 4:
				if ( xhr.status == 200 ) {
					fun(JSON.parse(xhr.responseText));
				} else {
					
				}
				break;
			default :
				break;
		}
	}
	var postdata="?";
	postdata = (function(value){
	　　for(var key in value){
	　　　　postdata += key+"="+value[key]+"&";
	　　};
	　　return postdata;
	}(data));
	postdata= postdata.TrimEnd("&");
	//xhr.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
	xhr.responseType="json"; 
	xhr.open("GET", url+postdata);
	xhr.send();
	return xhr;
};

//为了提高性能最好使用数组方法拼接字符串 
//创建一个StringBuffer类 
function StringBuffer(){
    this.strings = [];
};
StringBuffer.prototype.append = function (str) {
    this.strings.push(str);
};
StringBuffer.prototype.toString = function () {
    return this.strings.join('');
};
function CloseWaiting(timer)
{
	setTimeout(function(){
		plus.nativeUI.closeWaiting();
	},timer);
};
function OpenWindow(index,title,button,save)
{
	$("input").blur();
	if(index==200 && $("#divmsg200").length>0)
	{
		$("#divmsg200").show().attr("state","open");
	    setTimeout(function(){
	    $("#divmsg200").css("left","0px");
	    },10);
	}else if(index==201 && $("#divmsg201").length>0){
		$("#divmsg201").show().attr("state","open")
		setTimeout(function(){
	    $("#divmsg201").css("left","0px");
	    },10); 
	}
	else
	{
		if($("#divmsg"+index).length>0)
		{
			return;
		}
		var dialog = $('<div class="divmsg webview" state="open" id="divmsg'+index+'" pageindex="0" style="width:'+swidth+'px; background-color:#f3f3f3; position:absolute; height:'+sheight+'px;"><div class="title"><div id="back'+index+'" class="back">返回</div><div class="name">'+title+'</div><div id="button'+index+'" class="tool">'+button+'</div></div><div id="contentlist'+index+'" style="padding-top:45px;overflow-y: auto; height:'+sheight+'px; background-color:#fff; z-index:99; position: relative;"><div id="loading'+index+'" class="loading"><img src="img/loading.gif"/></div><div id="nlist" style="float:left; min-height: '+sheight+'px;"></div></div></div>');
		$("body").append(dialog);
        setTimeout(function(){
        $("#divmsg"+index).css("left","0px");
        get("back"+index).addEventListener("tap",function(){
		      			CloseWindow(index);
		      			if($(".customertool").length>0)
						{
							$(".customertool").hide();
						}
						if($("#divmsg100").length>0)
						{
							CloseMeng2();
						}
		    	});
		    	get("button"+index).addEventListener("tap",function(){
		      			save();
		    	});
        	document.querySelector("#divmsg"+index).addEventListener('transitionend', function () {
        	if($(this).attr("state")!="open"){
	            if(index==200 || index==201){
	    			$(this).hide();
	    		}else{
	    			$(this).remove();
	    		}
	    	}
        }, false);
		},10);
	}
};

function OpenWindow2(index,title,button,save)
{
	$("input").blur();
	if(index==200 && $("#divmsg200").length>0)
	{
		$("#divmsg200").show().attr("state","open");
	    setTimeout(function(){
	    $("#divmsg200").css("left","0px");
	    },10);
	}else if(index==201 && $("#divmsg201").length>0){
		$("#divmsg201").show().attr("state","open")
		setTimeout(function(){
	    $("#divmsg201").css("left","0px");
	    },10);
	}else
	{
		if($("#divmsg"+index).length>0)
		{
			return;
		}
		var dialog = $('<div class="divmsg webview" state="open" id="divmsg'+index+'" pageindex="0" style="width:'+swidth+'px;left:'+swidth+'px; background-color:#f3f3f3; height:'+sheight+'px; top:0px;"><div class="title"><div id="back'+index+'" class="back">返回</div><div class="name">'+title+'</div><div id="button'+index+'" class="tool">'+button+'</div></div><div id="contentlist'+index+'" style="padding-top:45px;overflow-y: auto; height:'+sheight+'px; background-color:#fff; z-index:99; position: relative;"><div id="loading'+index+'" class="loading"><img src="img/loading.gif"/></div><div id="nlist" style="float:left;"></div></div></div>');
		$("body").append(dialog);
		setTimeout(function(){
        $("#divmsg"+index).css("left","0px");
        get("back"+index).addEventListener("tap",function(){
	      			CloseWindow();
	      			if($(".customertool").length>0)
					{
						$(".customertool").hide();
					}
	    });
	    get("button"+index).addEventListener("tap",function(){
	      			save();
	    });
        document.querySelector("#divmsg"+index).addEventListener('transitionend', function () {
        	if($(this).attr("state")!="open"){
	    		if(index==200 || index==201){
	    			$(this).hide();
	    		}else{
	    			$(this).remove();
	    		}
	    	}
	    },false);
	    },10);
	}
};
//少了一个z-index:99;
function OpenWindow3(index,title,button,save)
{
	$("input").blur();
	if($("#divmsg"+index).length>0)
	{
		return;
	}
	if(index==200 && $("#divmsg200").length>0)
	{
		$("#divmsg200").show().attr("state","open");
	    setTimeout(function(){
	    $("#divmsg200").css("left","0px");
	    },10);
	}else
	{
		var dialog = $('<div class="divmsg webview" state="open" id="divmsg'+index+'" pageindex="0" style="width:'+swidth+'px;left:'+swidth+'px; background-color:#f3f3f3; height:'+sheight+'px; position:absolute;"><div class="title"><div id="back'+index+'" class="back">返回</div><div class="name">'+title+'</div><div id="button'+index+'" class="tool">'+button+'</div></div><div id="contentlist'+index+'" style="padding-top:45px;overflow-y: auto; height:'+sheight+'px; background-color:#fff; position: relative;"><div id="nlist" style="float:left; min-height: '+sheight+'px;"></div></div></div>');
		$("body").append(dialog);
		setTimeout(function(){
        $("#divmsg"+index).css("left","0px");
        get("back"+index).addEventListener("tap",function(){
	      			CloseWindow();
	      			if($(".customertool").length>0)
					{
						$(".customertool").hide();
					}
	    	});
	    	get("button"+index).addEventListener("tap",function(){
	      			save();
	    	});
        document.querySelector("#divmsg"+index).addEventListener('transitionend', function () {
        	if($(this).attr("state")!="open"){
	    		if(index==200 || index==201){
	    			$(this).hide();
	    		}else{
	    			$(this).remove();
	    		}
	    	}
	    },false);
	    },10);
	}
};

function OpenWindow4(index,title,button,save)
{
	$("input").blur();
	if(index==200 && $("#divmsg200").length>0)
	{
	    $("#divmsg200").show().attr("state","open");
	    setTimeout(function(){
	    $("#divmsg200").css("left","0px");
	    },10);
	}else if(index==201 && $("#divmsg201").length>0){
		$("#divmsg201").show().attr("state","open")
		setTimeout(function(){
	    $("#divmsg201").css("left","0px");
	    },10);
	}else
	{
		if($("#divmsg"+index).length>0)
		{
			return;
		}
		var dialog = $('<div class="divmsg webview" state="open" id="divmsg'+index+'" pageindex="0" style="width:'+swidth+'px;left:'+swidth+'px; background-color:#f3f3f3; position:absolute; height:'+sheight+'px;"><div class="title" style="z-index:101;"><div id="back'+index+'" class="back">返回</div><div class="name">'+title+'</div><div id="button'+index+'" class="tool">'+button+'</div></div><div id="contentlist'+index+'" style="padding-top:45px;overflow-y: auto; height:'+sheight+'px; background-color:#fff; z-index:100; position: relative;"><div id="loading'+index+'" class="loading"><img src="img/loading.gif"/></div></div></div>');
		$("body").append(dialog);
		setTimeout(function(){
        $("#divmsg"+index).css("left","0px");
        get("back"+index).addEventListener("tap",function(){
	      			CloseWindow();
	      			if($(".customertool").length>0)
					{
						$(".customertool").hide();
					}
	    	});
	    	get("button"+index).addEventListener("tap",function(){
	      			save();
	    	});
        document.querySelector("#divmsg"+index).addEventListener('transitionend', function () {
        	if($(this).attr("state")!="open"){
	    		if(index==200 || index==201){
	    			$(this).hide();
	    		}else{
	    			$(this).remove();
	    		}
	    	}
	    },false);
	    },10);
	}
};
//不真正关闭，只是hide，投票专用
function OpenWindow5(index,title,button,save,code)
{

		$("input").blur();
		var dialog;
		if($("#divmsg"+index).length==0)
		{
			dialog= $('<div class="divmsg webview" state="open" id="divmsg'+index+'" pageindex="0" style="width:'+swidth+'px;left:'+swidth+'px; background-color:#f3f3f3; position:absolute; height:'+sheight+'px;"><div class="title"><div id="back'+index+'" class="back">返回</div><div class="name">'+title+'</div><div id="button'+index+'" class="tool">'+button+'</div></div><div id="contentlist'+index+'" style="padding-top:45px;overflow-y: auto; height:'+sheight+'px; background-color:#fff; z-index:99; position: relative;"><div id="loading'+index+'" class="loading"><img src="img/loading.gif"/></div><div id="nlist" style="float:left; min-height: '+sheight+'px;"></div></div></div>');
			dialog.find("#contentlist"+index).html(code);
			$("body").append(dialog);
			Init_Votes();
			setTimeout(function(){
	        $("#divmsg"+index).css("left","0px");
	        get("back"+index).addEventListener("tap",function(){
		      			CloseWindow();
		   	});
		    get("button"+index).addEventListener("tap",function(){
		      			save();
		    });
	        document.querySelector("#divmsg"+index).addEventListener('transitionend', function () {
	        	if($(this).attr("state")=="hide"){
	        		$(this).hide();
		    	}
		    });
		    },10);
	    }else
	    {
	    	dialog=$("#divmsg"+index);
	    	dialog.show();
	    	setTimeout(function(){
	    		dialog.css("left","0px").attr("state","open");
	    	},10);
	    }
	
};
function OpenReply(o,fun)
{
	$("input").blur();
	if($("#divmsg300").length>0)
	{
	    $("#divmsg300").show().css("top",$(o).offset().top -12).css("left",(swidth-205)+"px").css("width","170").attr("state","open");
	}else{
		
		var dialog = $('<div class="divmsg" id="divmsg300" state="open" style="width:0px;left:'+(swidth-35)+'px;top:'+($(o).offset().top -12)+'px; background-color:#4c5154; position:absolute; height:40px; overflow:hidden; border-radius:3px; z-index:9999; transition-property: width , height; -webkit-transition-property: left,width; transition-duration:0.2s , 0.2s;-webkit-transition-duration:0.2s , 0.2s;"><div id="circlepraise" class="praise"><img src="img/praise.png"/></div><div class="lines"></div><div id="circlereply" class="replys"><img src="img/replys.png"/></div></div>');
		$("body").append(dialog);
	    setTimeout(function(){
	    	dialog.css("left",(swidth-205)+"px").css("width","170");
	    	document.querySelector("#divmsg300").addEventListener('transitionend', function () {
	        	if($(this).attr("state")=="close"){
	        		$(this).hide();
		    	}
		    });
	    },10);
	    fun();
	}
	if($(o).attr("praise")=="true")
	{
		$("#divmsg300 .praise img").attr("src","img/praised.png");
	}else{
		$("#divmsg300 .praise img").attr("src","img/praise.png");
	}
};

function OpenMeng(html) 
{
	$("input").blur();
	var dialog = $('<div id="meng2" class="meng" state="open" style="width:'+swidth+'px; height:'+sheight+'px; position:absolute; z-index:100;"></div><div class="divmsg" id="divmsg100" style="width:'+swidth+'px;left:0px; top:-200px; background-color:#fff; height:auto; position:fixed; z-index: 101;transition: all .3s; -webkit-transition: all .3s;-moz-transition: all .3s;-o-transition: all .3s;">'+html+'</div>');
	$("body").append(dialog);
	setTimeout(function(){
		$("#divmsg100").css("top","0px").prev().css("opacity","0.3");
	},10);
	document.querySelector("#divmsg100").addEventListener('transitionend', function () {
		if($("#divmsg100").prev().attr("state")=="close")
    	{
    		$(this).prev().remove();
    		$(this).remove();
    	}else{
    		if(plus.device.vendor!="Apple"){
    			$("#divmsg100 textarea").focus(); //安卓调出软键盘
    		}
    	}
	});

    //自动调出软键盘,如果是苹果设备，需要执行如下语句     苹果调出软键盘
    if(plus.device.vendor=="Apple")
    { 
    	var webView = plus.webview.currentWebview().nativeInstanceObject();
    	webView.plusCallMethod({"setKeyboardDisplayRequiresUserAction":false});
    	$("#divmsg100 textarea").focus(); 
    }
    
    get("close").addEventListener("tap",function(){
      			CloseMeng();
    });
    get("meng2").addEventListener("tap",function(){
      			CloseMeng();
    });
};

function OpenMeng2(html)
{
	$("input").blur();
	var dialog = $('<div id="meng" class="meng" state="open" style="width:'+swidth+'px; height:'+sheight+'px; position:absolute; z-index:99;"></div><div class="divmsg" id="divmsg100" style="width:'+swidth+'px;left:0px; top:-250px; background-color:#fff; height:auto; position:fixed; z-index: 99; transition: all .3s; -webkit-transition: all .3s;-moz-transition: all .3s;-o-transition: all .3s;">'+html+'</div>');
	$("body").append(dialog);
	setTimeout(function(){
		$("#divmsg100").css("top","0px").prev().css("opacity","0.3");
	},10);
	document.querySelector("#divmsg100").addEventListener('transitionend', function () {
		if($("#meng").attr("state")=="close")
    	{	 
    		$(this).prev().remove();
    		$(this).remove();
    		$("#divmsg1 .title").css("z-index","100");
    		$("#divmsg2 .title").css("z-index","100");
    	}
	});
	
 	get("meng").addEventListener("tap",function(){
      			CloseMeng2();
    });
};

function OpenMeng3(html,top)
{
	var dialog = $('<div id="meng" class="meng" state="open" style="width:'+swidth+'px; height:'+sheight+'px; position:absolute; z-index:99;"></div><div class="divmsg" id="divmsg100" style="width:'+swidth+'px;left:0px; opacity:0; top:'+top+'px; height:auto; position:fixed; z-index: 99; transition: all .3s; -webkit-transition: all .3s;-moz-transition: all .3s;-o-transition: all .3s;">'+html+'</div>');
	$("body").append(dialog);
	setTimeout(function(){
		$("#divmsg100").css("opacity","1").prev().css("opacity","0.3");
	},10);
	document.querySelector("#divmsg100").addEventListener('transitionend', function () {
		if($("#meng").attr("state")=="close")
    	{	 
    		$(this).prev().remove();
    		$(this).remove();
    		$("#divmsg1 .title").css("z-index","100");
    		$("#divmsg2 .title").css("z-index","100");
    	}
	});
 	get("meng").addEventListener("tap",function(){
      			CloseMeng3();
    });
};

function OpenMeng4(html)
{
	var dialog = $('<div id="meng" class="meng" state="open" style="width:'+swidth+'px; height:'+sheight+'px; position:absolute; z-index:99;"></div><div class="divmsg" id="divmsg100" style="width:'+swidth+'px;left:0px; bottom:-240px; background-color:#fff; height:auto; position:fixed; z-index: 99; transition: all .3s; -webkit-transition: all .3s;-moz-transition: all .3s;-o-transition: all .3s;">'+html+'</div>');
	$("body").append(dialog);
	setTimeout(function(){
		$("#divmsg100").css("bottom","0px").prev().css("opacity","0.3");
	},10);
	document.querySelector("#divmsg100").addEventListener('transitionend', function () {
		if($("#meng").attr("state")=="close")
    	{	 
    		$(this).prev().remove();
    		$(this).remove();
    	}
	});
 	$.each($("#schedulerepeatdate").attr("val").replace("最后一天","31").split(","),function(i,info){
 		$("#divmsg100 .square[val='"+info+"']").addClass("select").removeClass("ui-border");
 	});
 	mui(".divmsg").on("tap",".square",function(){
	    	if($(this).hasClass("select"))
	    	{
	    		if($("#divmsg100 .select").length==1)
	    		{
	    			return;
	    		}
	    		$(this).removeClass("select").addClass("ui-border");
	    	}else
	    	{
	    		$(this).addClass("select").removeClass("ui-border");
	    	}
	    	$("#schedulerepeatdate").attr("val",CRM.ListVal($("#divmsg100 .select"))+"");
	    	if($("#repeatrate_tool input").val()=="每周")
	    	{
	    		$("#schedulerepeatdate").val(CRM.ListHTML("#divmsg100 .select")+"");
	    	}else{
	    		$("#schedulerepeatdate").val(((CRM.ListHTML("#divmsg100 .select")+"").ReplaceAll(",","号,")+"号").replace("最后一天号","最后一天"));
	    	}
    	}
    );
 	get("meng").addEventListener("tap",function(){
      			CloseMeng4();
    });
    get("repeatsure").addEventListener("tap",function(){
      			CloseMeng4();
    });
    
};

function OpenScreen(html,fun,search)
{
	$("input").blur();
	var dialog;
	if($("#meng").attr("show")=="true"){
		HideScreen(155);
		return;
	}
	if($("#meng").length==0){
		dialog = $('<div id="meng" class="meng" show="true" style="width:'+swidth+'px; height:'+(sheight-90)+'px; top:90px; position:absolute; z-index:9;"></div><div class="divmsg" id="divmsg400" style="width:'+swidth+'px;left:0px; top:-110px; background-color:#fff; height:200px; position:fixed; z-index: 10; transition: all .3s; -webkit-transition: all .3s;-moz-transition: all .3s;-o-transition: all .3s;">'+html+'<div class="sure"><button id="clear" class="right5 ui-border-radius">重置</button><button id="sure" class="ui-border-radius">确定</button></div></div>');
		$("body").append(dialog);
	 	setTimeout(function(){
	 		$("#divmsg400").css("top","90px").prev().css("opacity","0.3");
	 	},10);
		document.querySelector("#divmsg400").addEventListener('transitionend', function () {
			if($("#meng").attr("show")=="false")
	    	{
	    		$(this).prev().hide();
	    		$(this).hide();
	    	}
		});
	    fun();
	    get("sure").addEventListener("tap",function(){
	    	if(search){
	    		search();
	    	}
	      	HideScreen(155);
	    });
	    get("clear").addEventListener("tap",function(){
			Clear_Form();
	    });
	    get("meng").addEventListener("tap",function(){
	      	HideScreen(155);
	    });
    }else
    {
    	$("#meng").show().attr("show","true");
    	$("#divmsg400").show();
    	setTimeout(function(){
	    	$("#divmsg400").css("top",90);
	    	$("#meng").css("opacity",0.3);
	 	},10);
    }
    
};

function OpenOAScreen(html,fun,search)
{
	$("input").blur();
	var dialog;
	var zindex=99;
	var height=250;
	if($("#divmsg1").length>0 && $("#divmsg1 .name").html().indexOf("审批列表")>-1)
	{
		height=280;		
	}
	if($("#divmsg2").length>0 && $("#divmsg2 .name").html().indexOf("代理商")>-1)
	{
		//height=270;	
		zindex=99;
	}
	if($("#meng").attr("show")=="true"){
		HideScreen(height);
		return;
	}
	if($("#meng").length==0){
		dialog = $('<div id="meng" class="meng" show="true" style="width:'+swidth+'px; height:'+(sheight-45)+'px; top:45px; position:absolute; z-index:'+zindex+';"></div><div class="divmsg" id="divmsg400" style="width:'+swidth+'px;left:0px; top:'+(45-height)+'px; background-color:#fff; height:'+height+'px; position:fixed; transition: all .3s; -webkit-transition: all .3s;-moz-transition: all .3s;-o-transition: all .3s; z-index: '+zindex+';">'+html+'<div class="sure"><button id="clear" class="right5 ui-border-radius">重置</button><button id="sure" class="ui-border-radius">确定</button></div></div>');
		$("body").append(dialog);
		setTimeout(function(){
	    	$("#divmsg400").css("top",45);
	    	$("#meng").css("opacity",0.3);
	 	},10);
	    fun();
	    get("sure").addEventListener("tap",function(){
	    	if(search){
	    		search();
	    	}
	      	HideScreen(height);
	    });
	    get("clear").addEventListener("tap",function(){
			Clear_Form();
	    });
	    get("meng").addEventListener("tap",function(){
	      	HideScreen(height);
	    });
	    document.querySelector("#meng").addEventListener('transitionend', function () {
	        	if($(this).attr("show")=="false"){
	        		$(this).hide();
	        		$(this).next().hide();
		    	}
		});
    }else
    {
    	$("#meng").show().attr("show","true");
    	$("#divmsg400").show();
    	setTimeout(function(){
	    	$("#divmsg400").css("top",45);
	    	$("#meng").css("opacity",0.3);
	 	},10);
    }
    
};

function OpenPhoto(path){
	var dialog = $('<div id="showphoto" state="open" style="width:100%;height:100%;background-color:#2d2c32; opacity:0; vertical-align:middle; text-align:center; line-height:'+sheight+'px; position:absolute;z-index:100; top:0px; transition: all .3s; -webkit-transition: all .3s;-moz-transition: all .3s;-o-transition: all .3s;"><img src="'+path+'" width="100%" style="vertical-align:middle;"/></div>');
	$("body").append(dialog);
	setTimeout(function(){
		dialog.css("opacity","1");
	},10);
	document.querySelector("#showphoto").addEventListener('transitionend', function () {
		if($("#showphoto").attr("state")=="close")
    	{	 
    		dialog.remove();
    	}
	});
	get("showphoto").addEventListener("tap",function(){
		dialog.css("opacity","0").attr("state","close");
	});
};
function SeePhoto(o){
	var dialog = $('<div id="showphoto" state="open" style="width:100%;height:100%;background-color:#2d2c32; opacity:0; vertical-align:middle; text-align:center; line-height:'+sheight+'px; position:absolute;z-index:100; top:0px; transition: all .3s; -webkit-transition: all .3s;-moz-transition: all .3s;-o-transition: all .3s;"><img src="'+o.src+'" width="100%" style="vertical-align:middle;"/><div style="width:100%; height:45px; background-color:#2d2c32;position:absolute;top:0px;" class="title"><div style="padding-left:0px; float:left; height:45px; line-height:45px; padding-left:15px;">返回</div><div id="up_delete" style="float:right;height:45px; line-height:45px; padding-top:6px; padding-right:15px;"><img src="img/remove.png" width="25"/></div></div></div>');
	$("body").append(dialog);
	$("#img_cover").height($("#img_cover").height()+"px");
	setTimeout(function(){
		dialog.css("opacity","1");
	},10);
	document.querySelector("#showphoto").addEventListener('transitionend', function () {
		if($("#showphoto").attr("state")=="close")
    	{	 
    		dialog.remove();
    	}
	});
	get("showphoto").addEventListener("tap",function(){
	    dialog.css("opacity","0").attr("state","close");
	});
	get("up_delete").addEventListener("tap",function(){
		stopEvent();
	    plus.nativeUI.confirm("要删除这张照片吗？", function(event){
								if(event.index==1)
								{
									o.remove();
									dialog.css("opacity","0").attr("state","close");
								}
							},"提示", ["取消","确认"]);
	});
	
};

function Clear_Form()
{
	$("#divmsg400 input[type='text']").val("").attr("touserid","");
	$("#divmsg400 select").val("");
	$($("#divmsg400 input[type='radio']")[0]).prop("checked", true); 
};

//index专为投票框设，解决关闭投票后，再打开可以初始化好
function CloseWindow(index)
{
	Close_RWindow();
	if($("#divmsg2").length>0 && $("#divmsg2 .name").html().indexOf("代理商")>-1) //代理商界面专用，防止影响到分享里，选择完同事后，关闭遮罩
	{
		CloseScreen();
	}
	if($("#divmsg200").length>0 && ($("#divmsg200").css("display")=="inline" || $("#divmsg200").css("display")=="block"))
	{
		map.hide();
		if(wsub){
			wsub.hide();
		}
		$("#divmsg200").css("left","100%").attr("state","close");
	    return;
   }if($("#divmsg201").length>0 && ($("#divmsg201").css("display")=="inline" || $("#divmsg201").css("display")=="block"))
	{
		mapnear.hide();
		$("#divmsg201").css("left","100%").attr("state","close");
	    return;
  }
	if($("#divmsg6").length>0)
	{
		$("#divmsg6").css("left","100%").attr("state","close");
	    return;
   }
	if($("#divmsg5").attr("state")=="open") //投票窗口专用
	{
		$("#divmsg5").css("left","100%").attr("state","hide");
		return;
	}
	
	if($("#divmsg4").length>0)
	{
		$("#divmsg4").css("left","100%").attr("state","close");
	    return;
   }
	if($("#divmsg3").length>0)
	{
		$("#divmsg3").css("left","100%").attr("state","close");
	    return;
   }
	if($("#divmsg2").length>0)
	{
		$("#divmsg2").css("left","100%").attr("state","close");
	    return;
   }
	if($("#divmsg1").length>0)
	{
		$("#divmsg1").css("left","100%").attr("state","close");
	    return; 
   }
	if($("#divmsg0").length>0)
	{
		$("#divmsg0").css("left","100%").attr("state","close");
	    return; 
   }
};

function CloseMeng()
{
    $("#divmsg100").css("top","-200px").prev().css("opacity","0").attr("state","close");
};
function CloseMeng2()
{   
    $("#divmsg100").css("top","-250px").prev().css("opacity","0").attr("state","close");
};
function CloseMeng3()
{
	if($("#divmsg100").length>0){	    
	    $("#divmsg100").css("opacity","0").prev().css("opacity","0").attr("state","close");
    }
};
function CloseMeng4()
{
	if($("#divmsg100").length>0){
	    $("#divmsg100").css("bottom","-240px").prev().css("opacity","0").attr("state","close");
    }
};

function CloseScreen()
{
	var o=$("#divmsg400");
	if(o.length>0)
	{
	    o.prev().fadeOut(300,function(){
	    	$(this).remove();
	    });
	    o.remove();
   }
};
function HideScreen(height)
{
    $("#divmsg400").css("top",(45-height)+"px").prev().css("opacity",0).attr("show","false");
};
function Get_Model(model) {
    switch (model) {
        case 1:
            return "分享";
            break;
        case 2:
            return "日志";
            break;
        case 3:
            return "任务";
            break;
        case 4:
            return "审批";
            break;
        case 5:
            return "公告";
            break;
        case 37:
            return "日程";
            break;
        default:
            return "";
    };
};

function Get_SignTime(signrule)
{
	if(signrule.ID!=0)
	{
		return signrule.UpTime1+"―"+signrule.DownTime1+"<br>"+signrule.UpTime2+"―"+signrule.DownTime2;		
	}else
	{
		if(User.RolePower.indexOf(",7,")>-1)
		{
			return "<a onclick='Set_SignRule()'>未设置</a>";
		}else{
			return "未设置";
		}
	}
};
//tools:工具栏
//top:下拉区域距离顶部距离

function OpenScroll(index,title,button,fun,save,tools,top)
{
	
	if($("#divmsg"+index).length>0)
	{
		return;
	}
	var vtop=25;
	if(top)
	{
		vtop=top;
	}
	var showcategory="hidden";
	if(title=="产品列表")
	{
		showcategory="";
	}
	var dialog = $('<div class="divmsg webview" state="open" id="divmsg'+index+'" pageindex="0" style="width:'+swidth+'px;left:'+swidth+'px; background-color:#fff; height:'+sheight+'px;position:absolute;"><div class="title"><div id="back'+index+'" class="back">返回</div><div id="divmsgname" class="name">'+title+'</div><div id="button'+index+'" class="tool">'+button+'</div><div id="category" class="category '+showcategory+'"><img src="img/category.png" width="18"/></div></div>'+tools+'<div id="wrapper'+index+'" style="padding-top:'+vtop+'px;"><div id="scroller"><div id="reflash'+index+'" class="reflash"></div><div id="contentlist'+index+'"></div><div id="loading'+index+'" class="loading"><img src="img/loading.gif"/></div></div></div></div>');
	$("body").append(dialog);
		setTimeout(function(){
        $("#divmsg"+index).css("left","0px");
        get("back"+index).addEventListener("tap",function(){
      			CloseWindow();
      			CloseScreen();
      			if($(".customertool").length>0)
				{
					$(".customertool").hide();
				}
				if($("#divmsg100").length>0)
				{
					CloseMeng2();
				}
    	});
    	get("button"+index).addEventListener("tap",function(){
      			save();
    	});
        document.querySelector("#divmsg"+index).addEventListener('transitionend', function () {
        if($(this).attr("state")!="open"){
    		$(this).remove();
    	}
    	},false);
    },10);
    var myScroll = new IScroll('#wrapper'+index, { 
		probeType: 3, 
		preventDefaultException: { tagName: /^(INPUT|TEXTAREA|BUTTON|SELECT|DIV|A|IMG)$/, className: /(^|\s)btn(\s|$)/ } //解决使用iscroll后，div:active{}无效的bug
	});

	pageindex=1;
	var y=0;
	var isdrag=true;
		get("divmsg"+index).addEventListener("dragend",function(){
		isdrag=false;
		$("#reflash"+index).html("");
		if (y >=40) {
        //下拉刷新效果
			//$("#contentlist"+index).html('');
			$("#loading"+index).html('<img src="img/loading.gif"/>');
			$("#divmsg"+index).attr("pageindex","0");
			pageindex=1;
        	fun(1); 
        }
		});
		get("divmsg"+index).addEventListener("dragstart",function(){
			isdrag=true;
		});
		myScroll.on("scroll",function(){
		  y=this.y;
		  
		  if(y > 0 && isdrag)
		  {
		  	  if(y<40)
		  	  {
		  	  $("#reflash"+index).html("下拉可以刷新");
		  	  }else if(y>=40)
		  	  {
		  	  	$("#reflash"+index).html("松开马上刷新");
		  	  }
		  }
		  else if (parseInt(y) == this.maxScrollY) {
                //上拉刷新效果
                //$("#screen").html(pageindex+"*"+parseInt($("#divmsg"+index).attr("pageindex"))); 测试用的
                if($("#loading"+index).html()!="没有更多了" && pageindex==parseInt($("#divmsg"+index).attr("pageindex")))
                {
                	
                	pageindex = parseInt($("#divmsg"+index).attr("pageindex"))+1;
	           		fun(pageindex);
                }
          }
	}); 
	return myScroll;
};

//tools:工具栏
//top:下拉区域距离顶部距离
//仅增加z-index:99999；
function OpenScroll2(index,title,button,fun,save,tools,top)
{
	if($("#divmsg"+index).length>0)
	{
		return;
	}
	var vtop=25;
	if(top)
	{
		vtop=top;
	}
	var dialog = $('<div class="divmsg webview" id="divmsg'+index+'" state="open" pageindex="0" style="width:'+swidth+'px;left:'+swidth+'px; background-color:#fff; height:'+sheight+'px; position: absolute;"><div class="title"><div id="back'+index+'" class="back">返回</div><div class="name">'+title+'</div><div id="button'+index+'" class="tool">'+button+'</div></div>'+tools+'<div id="wrapper'+index+'" style="padding-top:'+vtop+'px; z-index:99; position: absolute; background-color:#fff;"><div id="scroller"><div class="reflash" id="reflash'+index+'"></div><div id="contentlist'+index+'"></div><div id="loading'+index+'" class="loading"><img src="img/loading.gif"/></div></div></div></div>');
	$("body").append(dialog);
    setTimeout(function(){
        $("#divmsg"+index).css("left","0px");
        get("back"+index).addEventListener("tap",function(){
      			CloseWindow();
    	});
    	get("button"+index).addEventListener("tap",function(){
      			save();
    	});
        document.querySelector("#divmsg"+index).addEventListener('transitionend', function () {
        if($(this).attr("state")!="open"){
    		$(this).remove();
    	}
    	},false);
    },10);
    var myScroll = new IScroll('#wrapper'+index, { 
		probeType: 3, 
		preventDefaultException: { tagName: /^(INPUT|TEXTAREA|BUTTON|SELECT|DIV|A|IMG)$/, className: /(^|\s)btn(\s|$)/ } //解决使用iscroll后，div:active{}无效的bug
	});

	pageindex=1;
	var y=0;
	var isdrag=true;
		get("divmsg"+index).addEventListener("dragend",function(){
		isdrag=false;
		$("#reflash"+index).html("");
		if (y >=40) {
        //下拉刷新效果
			//$("#contentlist"+index).html('');
			$("#loading"+index).html('<img src="img/loading.gif"/>');
			$("#divmsg"+index).attr("pageindex","0");
			pageindex=1;
        	fun(1);
        }
		});
		get("divmsg"+index).addEventListener("dragstart",function(){
			isdrag=true;
		});
	myScroll.on("scroll",function(){
		  y=this.y;
		  if(y > 0 && isdrag)
		  {
		  	  if(y<40)
		  	  {
		  	  $("#reflash"+index).html("下拉可以刷新");
		  	  }else if(y>=40)
		  	  {
		  	  	$("#reflash"+index).html("松开马上刷新");
		  	  }
		  }
		  
		  else if (parseInt(y) == this.maxScrollY) {
                //上拉刷新效果
                
                if($("#loading"+index).html()!="没有更多了" && pageindex==parseInt($("#divmsg"+index).attr("pageindex")))
                {
                	pageindex = parseInt($("#divmsg"+index).attr("pageindex"))+1;
	           		fun(pageindex);
                }
          }
	}); 
	return myScroll;
};



function AtScroll(index,panel,fun)
{
	var myScroll = new IScroll('#wrapper'+index, {
		probeType: 3, 
		preventDefaultException: { tagName: /^(INPUT|TEXTAREA|BUTTON|SELECT|DIV|A|IMG)$/, className: /(^|\s)btn(\s|$)/ } //解决使用iscroll后，div:active{}无效的bug
	});

	pageindex=1;
	var y=0;
	var isdrag=true;
		get(panel).addEventListener("dragend",function(){
		isdrag=false;
		$("#reflash10").html("");
		if (y >=40) {
        //下拉刷新效果 
			$("#loading10").html('<img src="img/loading.gif"/>');
			$("#"+panel).attr("pageindex","0");
			pageindex=1;
        	fun(1);
        }
		});
		get(panel).addEventListener("dragstart",function(){
			isdrag=true;
		});
		myScroll.on("scroll",function(){
		  y=this.y;
		  
		  if(y > 0 && isdrag)
		  {
		  	  if(y<40)
		  	  {
		  	  $("#reflash10").html("下拉可以刷新");
		  	  }else if(y>=40)
		  	  {
		  	  	$("#reflash10").html("松开马上刷新");
		  	  }
		  }
		  else if (parseInt(y) == this.maxScrollY) {  
                //上拉刷新效果 
                if($("#loading10").html()!="没有更多了" && pageindex==parseInt($("#"+panel).attr("pageindex")))
                {
                	pageindex = parseInt($("#"+panel).attr("pageindex"))+1;
	           		fun(pageindex); 
                }
            }  
            
	}); 
	return myScroll;
};

function GetSize(size) {
    size = size / 1024;
    if (size < 1024) {
        return ChangeTwoDecimal(size) + " KB";
    }
    else {
        return ChangeTwoDecimal(size / 1024) + " MB";
    }
};
function ChangeTwoDecimal(x) {
    var f_x = parseFloat(x);
    if (isNaN(f_x)) {
        alert('function:changeTwoDecimal->parameter error');
        return false;
    }
    var f_x = Math.round(x * 100) / 100;
    return f_x;
};

function DownLoad(o,path){
			var url = domain + path;
		    var options = {method:"GET"};
			var dtask = plus.downloader.createDownload(url, options );
		    dtask.addEventListener("statechanged", function(task,status){
		    	if(!dtask){return;} 
		    	switch(task.state) {
		    		case 1: // 开始
		    		o.innerHTML="0%";
		    		break;
		    		case 2: // 已连接到服务器
					o.innerHTML="0%";
		    		break;
		    		case 3:	// 已接收到数据
		    			o.innerHTML = parseInt(task.downloadedSize/task.totalSize*100)+"%";
		    		break;
		    		case 4:	// 下载完成
		    			o.innerHTML="查看";
		    		break;
		    	}
		    } );
		    
			dtask.start();
		};
		
//获取文件图标
function GetICON(path) {
    var str = path.split(".");
    var ext = str[str.length - 1].toLowerCase();

    var css = "file_icon.jpg";
    switch (ext) {
    	case "jpg":
            css = "img_icon.jpg";
            break;
        case "jpeg":
            css = "img_icon.jpg";
            break;
        case "gif":
            css = "img_icon.jpg";
            break;
        case "png":
            css = "img_icon.jpg";
            break;
        case "doc":
            css = "word_icon.jpg";
            break;
        case "docx":
            css = "word_icon.jpg";
            break;
        case "xls":
            css = "excel_icon.jpg";
            break;
        case "xlsx":
            css = "excel_icon.jpg";
            break;
        case "ppt":
            css = "ppt_icon.jpg";
            break;
        case "pptx":
            css = "ppt_icon.jpg";
            break;
        case "txt":
            css = "txt_icon.jpg";
            break;
        case "pdf":
            css = "pdf_icon.jpg";
            break;
        case "rm":
            css = "mv_icon.jpg";
            break;
        case "rmvb":
            css = "mv_icon.jpg";
            break;
        case "avi":
            css = "mv_icon.jpg";
            break;
        case "wmv":
            css = "mv_icon.jpg";
            break;
        case "mp3":
            css = "mp3_icon.jpg";
            break;
        case "wma":
            css = "mp3_icon.jpg";
            break;
        case "aac":
            css = "mp3_icon.jpg";
            break;
        case "wav":
            css = "mp3_icon.jpg";
            break;
        case "cda":
            css = "mp3_icon.jpg";
            break;
        case "mid":
            css = "mp3_icon.jpg";
            break;
        case "rar":
            css = "rar_icon.jpg";
            break;
        case "zip":
            css = "rar_icon.jpg";
            break;
        default:
            css = "file_icon.jpg";
            break;
    }
    return css;      
 }
var initPhotoSwipeFromDOM = function(gallerySelector) {
	// parse slide data (url, title, size ...) from DOM elements 
	// (children of gallerySelector)
	var parseThumbnailElements = function(el) {
	    var thumbElements = el.childNodes,
	        numNodes = thumbElements.length,
	        items = [],
	        figureEl,
	        childElements,
	        linkEl,
	        size,
	        item;

	    for(var i = 0; i < numNodes; i++) {


	        figureEl = thumbElements[i]; // <figure> element

	        // include only element nodes 
	        if(figureEl.nodeType !== 1) {
				continue;
	        }

			linkEl = figureEl.children[0]; // <a> element
			
	        size = linkEl.getAttribute('data-size').split('x');

	        // create slide object
	        item = {
				src: linkEl.getAttribute('src'),
				w: parseInt(size[0], 10),
				h: parseInt(size[1], 10)
	        };

	        

	        if(figureEl.children.length > 1) {
	        	// <figcaption> content
	          	item.title = figureEl.children[1].innerHTML; 
	        }
 
	        if(linkEl.children.length > 0) {
	        	// <img> thumbnail element, retrieving thumbnail url
				item.msrc = linkEl.children[0].getAttribute('src');
	        } 
	       
			item.el = figureEl; // save link to element for getThumbBoundsFn
	        items.push(item);
	    }

	    return items;
	};

	// find nearest parent element
	var closest = function closest(el, fn) {
	    return el && ( fn(el) ? el : closest(el.parentNode, fn) );
	};

	// triggers when user clicks on thumbnail
	var onThumbnailsClick = function(e) {
	    e = e || window.event;
	    e.preventDefault ? e.preventDefault() : e.returnValue = false;

	    var eTarget = e.target || e.srcElement;

	    var clickedListItem = closest(eTarget, function(el) {
	        return el.tagName === 'FIGURE';
	    });

	    if(!clickedListItem) {
	        return;
	    }


	    // find index of clicked item
	    var clickedGallery = clickedListItem.parentNode,
	    	childNodes = clickedListItem.parentNode.childNodes,
	        numChildNodes = childNodes.length,
	        nodeIndex = 0,
	        index;

	    for (var i = 0; i < numChildNodes; i++) {
	        if(childNodes[i].nodeType !== 1) { 
	            continue; 
	        }

	        if(childNodes[i] === clickedListItem) {
	            index = nodeIndex;
	            break;
	        }
	        nodeIndex++;
	    }



	    if(index >= 0) {
	        openPhotoSwipe( index, clickedGallery );
	    }
	    return false;
	};

	// parse picture index and gallery index from URL (#&pid=1&gid=2)
	var photoswipeParseHash = function() {
		var hash = window.location.hash.substring(1),
	    params = {};

	    if(hash.length < 5) {
	        return params;
	    }

	    var vars = hash.split('&');
	    for (var i = 0; i < vars.length; i++) {
	        if(!vars[i]) {
	            continue;
	        }
	        var pair = vars[i].split('=');  
	        if(pair.length < 2) {
	            continue;
	        }           
	        params[pair[0]] = pair[1];
	    }

	    if(params.gid) {
	    	params.gid = parseInt(params.gid, 10);
	    }

	    if(!params.hasOwnProperty('pid')) {
	        return params;
	    }
	    params.pid = parseInt(params.pid, 10);
	    return params;
	};

	var openPhotoSwipe = function(index, galleryElement, disableAnimation) {
	    var pswpElement = document.querySelectorAll('.pswp')[0],
	        gallery,
	        options,
	        items;

		items = parseThumbnailElements(galleryElement);

	    // define options (if needed)
	    options = {
	        index: index,

			// define gallery index (for URL)
	        galleryUID: galleryElement.getAttribute('data-pswp-uid'),

	        getThumbBoundsFn: function(index) {
	            // See Options -> getThumbBoundsFn section of docs for more info
	            var thumbnail = items[index].el.getElementsByTagName('img')[0], // find thumbnail
	                pageYScroll = window.pageYOffset || document.documentElement.scrollTop,
	                rect = thumbnail.getBoundingClientRect(); 

	            return {x:rect.left, y:rect.top + pageYScroll, w:rect.width};
	        },

	        // history & focus options are disabled on CodePen
           	// remove these lines in real life: 
		   historyEnabled: false,
		   focus: false	

	    };

	    if(disableAnimation) {
	        options.showAnimationDuration = 0;
	    }

	    // Pass data to PhotoSwipe and initialize it
	    gallery = new PhotoSwipe( pswpElement, PhotoSwipeUI_Default, items, options);
	    gallery.init();
	};

	// loop through all gallery elements and bind events
	var galleryElements = document.querySelectorAll( gallerySelector );

	for(var i = 0, l = galleryElements.length; i < l; i++) {
		galleryElements[i].setAttribute('data-pswp-uid', i+1);
		galleryElements[i].onclick = onThumbnailsClick;
	}

	// Parse URL and open gallery if it contains #&pid=3&gid=1
	var hashData = photoswipeParseHash();
	if(hashData.pid > 0 && hashData.gid > 0) {
		openPhotoSwipe( hashData.pid - 1 ,  galleryElements[ hashData.gid - 1 ], true );
	}
};

//数字转金额大写
function Convert_Money(currencyDigits) {
    // Constants:
    var MAXIMUM_NUMBER = 99999999999.99;
    // Predefine the radix characters and currency symbols for output:
    var CN_ZERO = "零";
    var CN_ONE = "壹";
    var CN_TWO = "贰";
    var CN_THREE = "叁";
    var CN_FOUR = "肆";
    var CN_FIVE = "伍";
    var CN_SIX = "陆";
    var CN_SEVEN = "柒";
    var CN_EIGHT = "捌";
    var CN_NINE = "玖";
    var CN_TEN = "拾";
    var CN_HUNDRED = "佰";
    var CN_THOUSAND = "仟";
    var CN_TEN_THOUSAND = "万";
    var CN_HUNDRED_MILLION = "亿";
    var CN_SYMBOL = "人民币";
    var CN_DOLLAR = "元";
    var CN_TEN_CENT = "角";
    var CN_CENT = "分";
    var CN_INTEGER = "整";
    // Variables:
    var integral; // Represent integral part of digit number.
    var decimal; // Represent decimal part of digit number.
    var outputCharacters; // The output result.
    var parts;
    var digits, radices, bigRadices, decimals;
    var zeroCount;
    var i, p, d;
    var quotient, modulus;
    // Validate input string:
    currencyDigits = currencyDigits.toString();
    if (currencyDigits == "") {
        alert("Empty input!");
        return "";
    }
    if (currencyDigits.match(/[^,.\d]/) != null) {
        alert("Invalid characters in the input string!");
        return "";
    }
    if ((currencyDigits).match(/^((\d{1,3}(,\d{3})*(.((\d{3},)*\d{1,3}))?)|(\d+(.\d+)?))$/) == null) {
        alert("Illegal format of digit number!");
        return "";
    }
    // Normalize the format of input digits:
    currencyDigits = currencyDigits.replace(/,/g, ""); // Remove comma delimiters.
    currencyDigits = currencyDigits.replace(/^0+/, ""); // Trim zeros at the beginning.
    // Assert the number is not greater than the maximum number.
    if (Number(currencyDigits) > MAXIMUM_NUMBER) {
        alert("Too large a number to convert!");
        return "";
    }
    // Process the coversion from currency digits to characters:
    // Separate integral and decimal parts before processing coversion:
    parts = currencyDigits.split(".");
    if (parts.length > 1) {
        integral = parts[0];
        decimal = parts[1];
        // Cut down redundant decimal digits that are after the second.
        decimal = decimal.substr(0, 2);
    }
    else {
        integral = parts[0];
        decimal = "";
    }
    // Prepare the characters corresponding to the digits:
    digits = new Array(CN_ZERO, CN_ONE, CN_TWO, CN_THREE, CN_FOUR, CN_FIVE, CN_SIX, CN_SEVEN, CN_EIGHT, CN_NINE);
    radices = new Array("", CN_TEN, CN_HUNDRED, CN_THOUSAND);
    bigRadices = new Array("", CN_TEN_THOUSAND, CN_HUNDRED_MILLION);
    decimals = new Array(CN_TEN_CENT, CN_CENT);
    // Start processing:
    outputCharacters = "";
    // Process integral part if it is larger than 0:
    if (Number(integral) > 0) {
        zeroCount = 0;
        for (i = 0; i < integral.length; i++) {
            p = integral.length - i - 1;
            d = integral.substr(i, 1);
            quotient = p / 4;
            modulus = p % 4;
            if (d == "0") {
                zeroCount++;
            }
            else {
                if (zeroCount > 0) {
                    outputCharacters += digits[0];
                }
                zeroCount = 0;
                outputCharacters += digits[Number(d)] + radices[modulus];
            }
            if (modulus == 0 && zeroCount < 4) {
                outputCharacters += bigRadices[quotient];
            }
        }
        outputCharacters += CN_DOLLAR;
    }
    // Process decimal part if there is:
    if (decimal != "") {
        for (i = 0; i < decimal.length; i++) {
            d = decimal.substr(i, 1);
            if (d != "0") {
                outputCharacters += digits[Number(d)] + decimals[i];
            }
        }
    }
    // Confirm and return the final output string:
    if (outputCharacters == "") {
        outputCharacters = CN_ZERO + CN_DOLLAR;
    }
    if (decimal == "") {
        outputCharacters += CN_INTEGER;
    }
    outputCharacters = outputCharacters;
    return outputCharacters;
};

function Get_ICON(tableid){
	switch(tableid)
	{
		case 1:
			return "share.png";
			break;
		case 2:
			return "daily.png";
			break;
		case 3:
			return "task.png";
			break;
		case 4:
			return "examine.png";
			break;
		case 5:
			return "notice.png";
			break;
		case 9:
			return "customer.png";
			break;
		case 12:
			return "order.png";
			break;
		case 15:
			return "customer.png";
			break;
		case 37:
			return "schedule.png";
			break;
		
		default:
			return ""; 
	}
};

Date.prototype.Format = function (format) {
    var o = {
        "M+": this.getMonth() + 1, //month 
        "d+": this.getDate(), //day 
        "h+": this.getHours(), //hour 
        "m+": this.getMinutes(), //minute 
        "s+": this.getSeconds(), //second 
        "q+": Math.floor((this.getMonth() + 3) / 3), //quarter 
        "S": this.getMilliseconds() //millisecond 
    };
    if (/(y+)/.test(format)) {
        format = format.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
    }
    for (var k in o) {
        if (new RegExp("(" + k + ")").test(format)) {
            format = format.replace(RegExp.$1, RegExp.$1.length == 1 ? o[k] : ("00" + o[k]).substr(("" + o[k]).length));
        }
    }
    return format;
};
String.prototype.ReplaceAll = function (s1, s2) {
    return this.replace(new RegExp(s1, "gm"), s2);
};
String.prototype.ToDateMinute = function () {
    var date = new Date(this.replace(/-/g, "/"));
    return date.Format("MM-dd hh:mm");
};
String.prototype.ToDate = function () {
	if (this == "2015-01-01 00:00:00") {
        return "";
    }
    var date = new Date(this.replace(/-/g, "/"));
    return date.Format("yyyy-MM-dd");
};
String.prototype.ToDates = function () {
	if (this == "2015-01-01 00:00:00") {
        return "暂无";
    }
    var date = new Date(this.replace(/-/g, "/"));
    return date.Format("yyyy-MM-dd");
};
String.prototype.ToTime = function () {
    if (this == "2015-01-01 00:00:00") {
        return ""; 
    }
    var date = new Date(this.replace(/-/g, "/"));
    return date.Format("yyyy-MM-dd hh:mm");
};
String.prototype.ToTimes = function () {
    if (this == "2015-01-01 00:00:00") {
        return "暂无"; 
    }
    var date = new Date(this.replace(/-/g, "/"));
    return date.Format("yyyy-MM-dd hh:mm");
};
String.prototype.ToMonth = function () {
	if (this == "2015-01-01 00:00:00" || this=="") {
        return "暂无"; 
    }
    var date = new Date(this.replace(/-/g, "/"));
    return date.Format("MM月dd日");
};
String.prototype.Trim = function () {
    return this.replace(/(^\s*)|(\s*$)/g, "");
};
String.prototype.LTrim = function () {
    return this.replace(/(^\s*)/g, "");
};
String.prototype.RTrim = function () {
    return this.replace(/(\s*$)/g, "");
};
String.prototype.DHtml = function () {
    return this.replace(/<[^>]+>/g, "");
};
String.prototype.DHtmlButImg = function () {
    return this.replace(/<(?!img).*?>&<(?!br).*?>/g, "");
};
String.prototype.Cut = function () {
    var len=this.length;
    return len > 200 ? this.substring(0, 200) + '...<div class="expand"><a href="javascript:void(0)" onclick="ExpandStr(this,' + len + ')">展开正文（共' + len + '个字）</a></div>' : this;
};
String.prototype.RecoverText = function () {
    return this.ReplaceAll("<br>","\n");
};
String.prototype.TrimEnd = function (str) {
	var lastchar=this.substring(this.length-1,this.length);
	if(this!="" && lastchar==str)
	{
    	return this.substring(0,this.length-1);
    }else
    {
    	return this;
    }
};
String.prototype.TrimStar = function (str) {
	var firstchar=this.substring(0,1);
	if(this!="" && firstchar==str)
	{
    	return this.substring(1,this.length-1);
    }else
    {
    	return this;
    }
};
String.prototype.ToString = function (flag) {
	if(flag){
		return this;
	}else
	{
		if(this.Trim()=="" || this=="null")
		{
			return "暂无";
		}else
		{
			return this;
		}
	}
};
String.prototype.toFixed = function (flag) {
	return parseFloat(this).toFixed(flag);
};

String.prototype.TrimStart = function (str) {
	var firstchar=this.substring(0,1);
	if(this!="" && firstchar==str)
	{
    	return this.substring(1,this.length);
    }else
    {
    	return this;
    }
};
function ExpandStr(o,len) {
    $(o).parent().parent().html($(o).parent().parent().prev().html() + '<div class="expand"><a href="javascript:void(0)" onclick="CloseStr(this,'+len+')">关闭正文（共'+len+'个字）</a></div>');
    myScroll1.refresh();
};
function CloseStr(o,len) {
    $(o).parent().parent().html($(o).parent().parent().prev().html().DHtml().Cut());
    myScroll1.refresh();
};
var CRM = {
	ListVal: function (list) { //获取所有集合的val
        var array = new Array();
        list.each(function () {
            array.push($(this).attr("val"));
        });
        return array;
    },ItemID: function (id) {
        var array = new Array();
        $(id + " input:checked").each(function () {
            array.push($(this).val());
        });
        return array;
    },ListValue: function (list) { //获取所有集合的value
        var array = new Array();
        list.each(function () {
            array.push($(this).val());
        });
        return array;
    },ListHTML: function (id) { //获取所有集合的HTML
        var array = new Array();
        $(id).each(function () {
            array.push($(this).html());
        });
        return array;
    }
};

//检查输入的数字是否正确
function Check_Money(o) {
    if (o.value.Trim()!="") {
        if (isNaN(o.value)) {
            if ($(o).attr("val")+"" !="undefined") {
                o.value = $(o).attr("val");
            }
            else {
                o.value = "0";
            }
        }
        else {
            if (parseFloat(o.value) <= 0) {
                $(o).attr("val", 0);
                $(o).val(0);
            } else {
                $(o).attr("val", o.value);
            }
        }
    }
};

//计算订单价格
function Cal_POrder(o) {
    var tr = $(o).parent().parent().parent();
    var costprice = tr.find("td:eq(2)").html();
    var count = tr.find("td:eq(3)").find("input").val();
    var percent = tr.find("td:eq(4)").find("input").val();
    tr.find("td:eq(5)").html((parseFloat(costprice * count * percent) / 100).toFixed(2));
    //合计
    /*
    var allprice = 0;
    tr.parent().find("tr:gt(0)").each(function (i, row) {
        if ($(row).find("td:eq(1) input").attr("itemid") > 0) {
            allprice += parseFloat($(row).find("td:eq(6)").html());
        }
    });
    $(".porder_allprice font").html(allprice.toFixed(2) + "元");
    */
};

function Last(o)
{
	o.focus();
	var len = o.value.length;
	if (document.selection) {
		var sel = o.createTextRange();
		sel.moveStart('character', len);
		sel.collapse();
		sel.select();
	} else if (typeof o.selectionStart == 'number' && typeof o.selectionEnd == 'number') {
		o.selectionStart = o.selectionEnd = len;
	}
};

//功能：将浮点数四舍五入，取小数点后2位  
function ToDecimal(x) {
    var f = parseFloat(x);
    if (isNaN(f)) {
        return;
    }
    f = Math.round(x * 100) / 100;
    return f;
};


function DateDiff(interval, date1, date2) {
    try {
        var objInterval = {'Y':1000 * 60 * 60 * 24 * 365, 'D': 1000 * 60 * 60 * 24, 'H': 1000 * 60 * 60, 'M': 1000 * 60, 'S': 1000, 'T': 1 };
        interval = interval.toUpperCase();
        var dt1 = Date.parse(date1.replace(/-/g, '/'));
        var dt2 = Date.parse(date2.replace(/-/g, '/'));
        return parseInt((dt2 - dt1) / eval('(objInterval.' + interval + ')'));
    }
    catch (e) {
        return e.message;
    }
};

//得到事件
function getEvent() {
    try {
        if (window.event) { return window.event; }
        func = getEvent.caller;
        while (func != null) {
            var arg0 = func.arguments[0];
            if (arg0) {
                if ((arg0.constructor == Event || arg0.constructor == MouseEvent
                || arg0.constructor == KeyboardEvent)
                || (typeof (arg0) == "object" && arg0.preventDefault
                && arg0.stopPropagation)) {
                    return arg0;
                }
            }
            func = func.caller;
        }
        return null;
    } catch (ex) { 
    
    }
};
//阻止冒泡
function stopEvent(event) {
    try {
        var e = getEvent();
        if (event) {e = event;}
        if (window.event) {
            //e.returnValue=false;//阻止自身行为
            e.cancelBubble = true; //阻止冒泡
        } else if (e.preventDefault) {
            //e.preventDefault();//阻止自身行为
            e.stopPropagation(); //阻止冒泡
        }
    } catch (ex) {

    }
};

function RUndefined(str){
	if(str+""=="undefined")
	{
		return "";
	}else
	{
		return str;
	}
};

function ScrollTop(id){
	if(id)
	{
		id=1;
	}else{
		id=2;
	}
	if(plus.device.vendor=="Apple")
    {
    	
		var height = get("contentlist"+id).scrollTop;
		window.setTimeout(function () {  
		    document.activeElement.scrollIntoViewIfNeeded();  
		    $('#contentlist'+id).animate({   
			scrollTop : height
			}, "slow");
		    }, 300);
	}
};
// 下载wgt文件
function AutoDownWgt(){
	var wgtUrl= domain + "/upgrade/qiyedaishu.wgt";
    plus.downloader.createDownload( wgtUrl, {filename:"_doc/update/"}, function(d,status){
        if ( status == 200 ) { 
            AutoInstallWgt(d.filename); // 安装wgt包
        } else {
        }

    }).start();
};

// 更新应用资源
function AutoInstallWgt(path){
    plus.runtime.install(path,{},function(){
    },function(e){
    });
};


// 下载wgt文件
function DownWgt(file){
	OpenUpGrade();
	var wgtUrl= domain + "/upgrade/"+file;
    var dtask=plus.downloader.createDownload( wgtUrl, {filename:"_doc/update/"}, function(d,status){
        if ( status == 200 ) {
            InstallWgt(d.filename); // 安装wgt包
        } else {
            plus.nativeUI.alert("下载更新文件失败！");
        }
        plus.nativeUI.closeWaiting();
    });
    dtask.addEventListener("statechanged", function(task,status){
		    	if(!dtask){return;} 
		    	switch(task.state) {
		    		case 1: // 开始
		    		//o.innerHTML="0%";
		    		break;
		    		case 2: // 已连接到服务器
					//o.innerHTML="0%";
		    		break;
		    		case 3:	// 已接收到数据
		    			get("divmsg100").innerHTML = "更新进度："+parseInt(task.downloadedSize/task.totalSize*100)+" %";
		    		break;
		    		case 4:	// 下载完成
		    			$("#meng,#divmsg100").remove();
		    		break;
		    	}
	});
	dtask.start();
};

// 更新应用资源
function InstallWgt(path){
    plus.runtime.install(path,{},function(){
        plus.nativeUI.alert("升级成功！",function(){
            plus.runtime.restart();
        });
    },function(e){
        plus.runtime.restart();
    });
};

function OpenUpGrade()
{
	var dialog = $('<div id="meng" class="meng" style="width:'+swidth+'px; height:'+sheight+'px; position:absolute; z-index:99;"></div><div class="divmsg" id="divmsg100" style="width:70%; left:15%; top:'+(sheight-50)/2+'px; background-color:#fff; height:50px; border-radius:5px; text-align:center;font-size:14px; line-height:50px; position:fixed; z-index: 99;">更新进度：0 %</div>');
	$("body").append(dialog);
};


function GetNewPos(fun){
		var point={};
		pos_map.getUserLocation(function(state,point){
			if(0==state){
	      		Get_Address(point,fun);
      		}else{
      			point.address="";
				point.latitude="";
		        point.longitude="";
		        Get_Address(point,fun);
      		}
		});
};

function Get_Address(point,fun){
	var data = {};
	data.act = "Get_Address";
	data.latlng=point.latitude+","+point.longitude;
	data.userid=userid;
	data.comid=comid;
	data.source=source;
	data.sign=GetSign(data.act);
	mui.getJSON(index_domain, data, function(json) {
		if(json.state)
		{
			point.address=json.data;
			if(fun){
				fun(point);
			}
		}else
		{
			
		}						
	});	
};

function GetSign(act){
	return md5("account=QiYeDaiShu_CLIENT&act="+act+"&key=265B6B86CA6E43A552G363078D5ADCFE");
};

//当月天数
function DayNumOfMonth(Year, Month) {
    var d = new Date(Year, Month, 0);
    return d.getDate();
};

function GetWeek(str)
{
	return str.TrimStar(",").TrimEnd(",").replace("1","周一").replace("2","周二").replace("3","周三").replace("4","周四").replace("5","周五").replace("6","周六").replace("7","周日");
};

function GetDateStr(AddDayCount) { 
	var dd = new Date(); 
	dd.setDate(dd.getDate()+AddDayCount);//获取AddDayCount天后的日期 
	var y = dd.getFullYear();
	var m = dd.getMonth()+1;//获取当前月份的日期 
	var d = dd.getDate(); 
	return y+"-"+m+"-"+d; 
}; 
function GetMonthStr(AddDayCount) { 
	var dd = new Date(); 
	dd.setMonth(dd.getMonth()+AddDayCount);//获取AddDayCount天后的日期 
	var y = dd.getFullYear();
	var m = dd.getMonth()+1;//获取当前月份的日期 
	var d = dd.getDate(); 
	return y+"-"+m+"-"+d; 
}; 

function CalTax(allmoney)
{
            allmoney -= 3500;
            if (allmoney > 0 && allmoney <= 1500)
            {
                return allmoney * 0.03;
            }
            else if (allmoney > 1500 && allmoney <= 4500)
            {
                return allmoney * 0.1 - 105;
            }
            else if (allmoney > 4500 && allmoney <= 9000)
            {
                return allmoney * 0.2 - 555;
            }
            else if (allmoney > 9000 && allmoney <= 35000)
            {
                return allmoney * 0.25 - 1005;
            }
            else if (allmoney > 35000 && allmoney <= 55000)
            {
                return allmoney * 0.3 - 2775;
            }
            else if (allmoney > 55000 && allmoney <= 80000)
            {
                return allmoney * 0.35 - 5505;
            }
            else if (allmoney > 80000)
            {
                return allmoney * 0.45 - 13505;
            }
            else
            {
                return 0;
            }
};